/*********************/
/** SenseLight.java */
/*********************/
package atag.apps.mainApp;

import atag.runtime.DataItem;
import atag.runtime.DataPool;
import atag.runtime.NodeInfo;
import atag.runtime.sensors.LightSensor;

public class SenseLight implements Runnable {

    private DataPool m_dataPool;
    private NodeInfo m_myState;
    private LightSensor myLight;

    /** Creates a new instance of SenseLight */
    public SenseLight(DataPool dp, NodeInfo myconfig) {
        m_dataPool = dp;
        m_myState = myconfig;
        myLight=new LightSensor();
    }

    public synchronized void run() {

        try {
            while (true) {

                Thread.sleep(10000);
                handleExpiryOfTimer();
            }
        } catch (InterruptedException e) {
            return;
        }
    }

    private void handleExpiryOfTimer() {
        LightReading m_LightReading = new LightReading();
        m_LightReading.setID(this.m_myState.getMyId());
        m_LightReading.setLightReading(this.myLight.getCurrentReading());

        this.m_myState.debugPrint("[SenseLight] Got a ID: " + this.m_myState.getMyId()
                + " Light Reading : " + this.myLight.getCurrentReading());

        m_dataPool.putData(new DataItem(IDConstants.D_LIGHTREADING,
                IDConstants.T_SENSELIGHT, m_LightReading));
    }
}
